﻿using Microsoft.EntityFrameworkCore;
using TyNetCoreBlog.Models.Entities;

namespace TyNetCoreBlog.Models.Data
{
    public class AppDbContext : DbContext
    {
        public AppDbContext(DbContextOptions<AppDbContext> options)
            : base(options)
        {}

        public DbSet<Blog> Blogs { get; set; }
        public DbSet<Category> Categories { get; set; }
        public DbSet<Tag> Tags { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<FriendlyLink> FriendLinks { get; set; }


        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //配置多对多关系
            modelBuilder.Entity<BlogTag>().HasKey(x => new { x.BlogId, x.TagId });

            //初始化数据
            modelBuilder.SeedData();
        }


    }
}
